home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_008 / src / hack.pri.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  13KB  |  582 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* hack.pri.c version 1.0.1 - tiny change in mnewsym() - added time */
  3.  
  4. #include "hack.h"
  5. #include <stdio.h>
  6. xchar scrlx, scrhx, scrly, scrhy;   /* corners of new area on screen */
  7.  
  8. extern char *hu_stat[];   /* in eat.c */
  9.  
  10. swallowed()
  11. {
  12.    char *ulook = "|@|";
  13.    ulook[1] = u.usym;
  14.  
  15.    cls();
  16.    curs(u.ux-1, u.uy+1);
  17.    myprintf("/-\\");
  18.    curx = u.ux+2;
  19.    curs(u.ux-1, u.uy+2);
  20.    myprintf(ulook);
  21.    curx = u.ux+2;
  22.    curs(u.ux-1, u.uy+3);
  23.    myprintf("\\-/");
  24.    curx = u.ux+2;
  25.    u.udispl = 1;
  26.    u.udisx = u.ux;
  27.    u.udisy = u.uy;
  28. }
  29.  
  30.  
  31. /*VARARGS1*/
  32. boolean panicking;
  33.  
  34. panic(str,a1,a2,a3,a4,a5,a6)
  35. char *str;
  36. {
  37.    if(panicking++) hackexit(1);   /* avoid loops */
  38.    home();
  39.    myprintf(" Suddenly, the dungeon collapses.\n");
  40.    myprintf(" ERROR:  ");
  41.    myprintf(str,a1,a2,a3,a4,a5,a6);
  42. /* if(fork()) */
  43.       done("panic");
  44. /* else          */
  45. /*    abort();   */   /* generate core dump */
  46. }
  47.  
  48. atl(x,y,ch)
  49. register int x,y;
  50. {
  51.    register struct rm *crm = &levl[x][y];
  52.  
  53.    if(x<0 || x>COLNO-1 || y<0 || y>ROWNO-1)
  54.       panic("at(%d,%d,%c_%o_)",x,y,ch,ch);
  55.    if(crm->seen && crm->scrsym == ch) return;
  56.    crm->scrsym = ch;
  57.    crm->new = 1;
  58.    on_scr(x,y);
  59. }
  60.  
  61. on_scr(x,y)
  62. register int x,y;
  63. {
  64.    if(x<scrlx) scrlx = x;
  65.    if(x>scrhx) scrhx = x;
  66.    if(y<scrly) scrly = y;
  67.    if(y>scrhy) scrhy = y;
  68. }
  69.  
  70. /* call: (x,y) - display
  71.    (-1,0) - close (leave last symbol)
  72.    (-1,-1)- close (undo last symbol)
  73.    (-1,let)-open: initialize symbol
  74.    (-2,let)-change let
  75. */
  76.  
  77. tmp_at(x,y) schar x,y; {
  78. static schar prevx, prevy;
  79. static char let;
  80.    if((int)x == -2){   /* change let call */
  81.       let = y;
  82.       return;
  83.    }
  84.    if((int)x == -1 && (int)y >= 0){   /* open or close call */
  85.       let = y;
  86.       prevx = -1;
  87.       return;
  88.    }
  89.    if(prevx >= 0 && cansee(prevx,prevy)) {
  90.       delay_output();
  91.       prl(prevx, prevy);   /* in case there was a monster */
  92.       at(prevx, prevy, levl[prevx][prevy].scrsym);
  93.    }
  94.    if(x >= 0){   /* normal call */
  95.       if(cansee(x,y)) at(x,y,let);
  96.       prevx = x;
  97.       prevy = y;
  98.    } else {   /* close call */
  99.       let = 0;
  100.       prevx = -1;
  101.    }
  102. }
  103.  
  104. /* like the previous, but the symbols are first erased on completion */
  105. Tmp_at(x,y) schar x,y; {
  106. static char let;
  107. static xchar cnt;
  108. static coord tc[COLNO];      /* but watch reflecting beams! */
  109. register int xx,yy;
  110.    if((int)x == -1) {
  111.       if(y > 0) {   /* open call */
  112.          let = y;
  113.          cnt = 0;
  114.          return;
  115.       }
  116.       /* close call (do not distinguish y==0 and y==-1) */
  117.       while(cnt--) {
  118.          xx = tc[cnt].x;
  119.          yy = tc[cnt].y;
  120.          prl(xx, yy);
  121.          at(xx, yy, levl[xx][yy].scrsym);
  122.       }
  123.       cnt = let = 0;   /* superfluous */
  124.       return;
  125.    }
  126.    if((int)x == -2) {   /* change let call */
  127.       let = y;
  128.       return;
  129.    }
  130.    /* normal call */
  131.    if(cansee(x,y)) {
  132.       if(cnt) delay_output();
  133.       at(x,y,let);
  134.       tc[cnt].x = x;
  135.       tc[cnt].y = y;
  136.       if(++cnt >= COLNO) panic("Tmp_at overflow?");
  137.       levl[x][y].new = 0;   /* prevent pline-nscr erasing --- */
  138.    }
  139. }
  140.  
  141. at(x,y,ch)
  142. register xchar x,y;
  143. char ch;
  144. {
  145. #ifndef lint
  146.    /* if xchar is unsigned, lint will complain about  if(x < 0)  */
  147.    if(x < 0 || x > COLNO-1 || y < 0 || y > ROWNO-1)
  148.       panic("At gets 0%o at %d %d(%d %d)",ch,x,y,u.ux,u.uy);
  149. #endif lint
  150.    if(!ch) {
  151.       home();
  152.       myprintf("At gets null at %2d %2d.",x,y);
  153.       curx = ROWNO+1;
  154.       return;
  155.    }
  156.    y += 2;
  157.    curs(x,y);
  158.    myputchar(ch);
  159.    curx++;
  160. }
  161.  
  162. prme(){
  163.    if(!Invis) at(u.ux,u.uy,u.usym);
  164. }
  165.  
  166. docrt()
  167. {
  168.    register int x,y;
  169.    register struct rm *room;
  170.    register struct monst *mtmp;
  171.  
  172.    if(u.uswallow) {
  173.       swallowed();
  174.       return;
  175.    }
  176.    cls();
  177.    if(!Invis){
  178.       levl[(u.udisx = u.ux)][(u.udisy = u.uy)].scrsym = u.usym;
  179.       levl[u.udisx][u.udisy].seen = 1;
  180.       u.udispl = 1;
  181.    } else   u.udispl = 0;
  182.  
  183.    /* %% - is this really necessary? */
  184.    for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  185.       if(mtmp->mdispl && !(room = &levl[mtmp->mx][mtmp->my])->new &&
  186.          !room->seen)
  187.          mtmp->mdispl = 0;
  188.  
  189.    for(y = 0; y < ROWNO; y++)
  190.       for(x = 0; x < COLNO; x++)
  191.          if((room = &levl[x][y])->new) {
  192.             room->new = 0;
  193.             at(x,y,room->scrsym);
  194.          } else if(room->seen) at(x,y,room->scrsym);
  195.    scrlx = COLNO;
  196.    scrly = ROWNO;
  197.    scrhx = scrhy = 0;
  198.    flags.botlx = 1;
  199.    bot();
  200. }
  201.  
  202. docorner(xmin,ymax) register int xmin,ymax; {
  203.    register int x,y;
  204.    register struct rm *room;
  205.    if(u.uswallow) {   /* Can be done more efficiently */
  206.       swallowed();
  207.       return;
  208.    }
  209.    for(y = 0; y < ymax; y++) {
  210.       curs(xmin,y+2);
  211.       cl_end();
  212.       for(x = xmin; x < COLNO; x++) {
  213.          if((room = &levl[x][y])->new) {
  214.             room->new = 0;
  215.             at(x,y,room->scrsym);
  216.          } else if(room->seen) at(x,y,room->scrsym);
  217.       }
  218.    }
  219. }
  220.  
  221. pru()
  222. {
  223.    if(u.udispl && (Invis || u.udisx != u.ux || u.udisy != u.uy))
  224.       /* if(! levl[u.udisx][u.udisy].new) */
  225.          if(!vism_at(u.udisx, u.udisy))
  226.             newsym(u.udisx, u.udisy);
  227.    if(Invis) {
  228.       u.udispl = 0;
  229.       prl(u.ux,u.uy);
  230.    } else
  231.    if(!u.udispl || u.udisx != u.ux || u.udisy != u.uy) {
  232.       atl(u.ux, u.uy, u.usym);
  233.       u.udispl = 1;
  234.       u.udisx = u.ux;
  235.       u.udisy = u.uy;
  236.    }
  237.    levl[u.ux][u.uy].seen = 1;
  238. }
  239.  
  240. #ifndef NOWORM
  241. #include   "def.wseg.h"
  242. extern struct wseg *m_atseg;
  243. #endif NOWORM
  244.  
  245. /* print a position that is visible for @ */
  246. prl(x,y)
  247. {
  248.    register struct rm *room;
  249.    register struct monst *mtmp;
  250.    register struct obj *otmp;
  251.  
  252.    if(x == u.ux && y == u.uy && !Invis) {
  253.       pru();
  254.       return;
  255.    }
  256.    room = &levl[x][y];
  257.    if((!room->typ) || (room->typ<DOOR && levl[u.ux][u.uy].typ == CORR))
  258.       return;
  259.    if((mtmp = m_at(x,y)) && !mtmp->mhide &&
  260.       (!mtmp->minvis || See_invisible)) {
  261. #ifndef NOWORM
  262.       if(m_atseg)
  263.          pwseg(m_atseg);
  264.       else
  265. #endif NOWORM
  266.       pmon(mtmp);
  267.    }
  268.    else if(otmp = o_at(x,y))
  269.       atl(x,y,otmp->olet);
  270.    else if(mtmp && (!mtmp->minvis || See_invisible)) {
  271.       /* must be a hiding monster, but not hiding right now */
  272.       /* assume for the moment that long worms do not hide */
  273.       pmon(mtmp);
  274.    }
  275.    else if(g_at(x,y,fgold)) atl(x,y,'$');
  276.    else if(!room->seen || room->scrsym == ' ') {
  277.       room->new = room->seen = 1;
  278.       newsym(x,y);
  279.       on_scr(x,y);
  280.    }
  281.    room->seen = 1;
  282. }
  283.  
  284. char
  285. news0(x,y)
  286. register xchar x,y;
  287. {
  288.    register struct obj *otmp;
  289.    register struct gen *gtmp;
  290.    struct rm *room;
  291.    register char tmp;
  292.  
  293.    room = &levl[x][y];
  294.    if(!room->seen) tmp = ' ';
  295.    else if(!Blind && (otmp = o_at(x,y))) tmp = otmp->olet;
  296.    else if(!Blind && g_at(x,y,fgold)) tmp = '$';
  297.    else if(x == xupstair && y == yupstair) tmp = '<';
  298.    else if(x == xdnstair && y == ydnstair) tmp = '>';
  299.    else if((gtmp = g_at(x,y,ftrap)) && (gtmp->gflag & SEEN)) tmp = '^';
  300.    else switch(room->typ) {
  301.    case SCORR:
  302.    case SDOOR:
  303.       tmp = room->scrsym;   /* %% wrong after killing mimic ! */
  304.       break;
  305.    case HWALL:
  306.       tmp = '-';
  307.       break;
  308.    case VWALL:
  309.       tmp = '|';
  310.       break;
  311.    case LDOOR:
  312.    case DOOR:
  313.       tmp = '+';
  314.       break;
  315.    case CORR:
  316.       tmp = CORR_SYM;
  317.       break;
  318.    case ROOM:
  319.       if(room->lit || cansee(x,y) || Blind) tmp = '.';
  320.       else tmp = ' ';
  321.       break;
  322.    default: tmp = ERRCHAR;
  323.    }
  324.    return(tmp);
  325. }
  326.  
  327. newsym(x,y)
  328. register int x,y;
  329. {
  330.    atl(x,y,news0(x,y));
  331. }
  332.  
  333. /* used with wand of digging: fill scrsym and force display */
  334. mnewsym(x,y)
  335. register int x,y;
  336. {
  337.     register struct monst *mtmp = m_at(x,y);
  338.     register struct rm *room;
  339.     char newscrsym;
  340.  
  341.    if(!mtmp || (mtmp->minvis && !See_invisible) ||
  342.           (mtmp->mhide && o_at(x,y))){
  343.         room = &levl[x][y];
  344.         newscrsym = news0(x,y);
  345.         if(room->scrsym != newscrsym) {
  346.             room->scrsym = newscrsym;
  347.             room->seen = 0;
  348.         }
  349.    }
  350. }
  351.  
  352. nosee(x,y)
  353. register int x,y;
  354. {
  355.    register struct rm *room;
  356.  
  357.    room = &levl[x][y];
  358.    if(room->scrsym == '.' && !room->lit && !Blind) {
  359.       room->scrsym = ' ';
  360.       room->new = 1;
  361.       on_scr(x,y);
  362.    }
  363. }
  364.  
  365. #ifndef QUEST
  366. prl1(x,y)
  367. register int x,y;
  368. {
  369.    if(u.dx) {
  370.       if(u.dy) {
  371.          prl(x-(2*u.dx),y);
  372.          prl(x-u.dx,y);
  373.          prl(x,y);
  374.          prl(x,y-u.dy);
  375.          prl(x,y-(2*u.dy));
  376.       } else {
  377.          prl(x,y-1);
  378.          prl(x,y);
  379.          prl(x,y+1);
  380.       }
  381.    } else {
  382.       prl(x-1,y);
  383.       prl(x,y);
  384.       prl(x+1,y);
  385.    }
  386. }
  387.  
  388. nose1(x,y)
  389. register int x,y;
  390. {
  391.    if(u.dx) {
  392.       if(u.dy) {
  393.          nosee(x,u.uy);
  394.          nosee(x,u.uy-u.dy);
  395.          nosee(x,y);
  396.          nosee(u.ux-u.dx,y);
  397.          nosee(u.ux,y);
  398.       } else {
  399.          nosee(x,y-1);
  400.          nosee(x,y);
  401.          nosee(x,y+1);
  402.       }
  403.    } else {
  404.       nosee(x-1,y);
  405.       nosee(x,y);
  406.       nosee(x+1,y);
  407.    }
  408. }
  409. #endif QUEST
  410.  
  411. vism_at(x,y) register int x,y; {
  412. register struct monst *mtmp;
  413. register int csi = (See_invisible != 0);
  414.    return((x == u.ux && y == u.uy && (!Invis || csi)) ? 1 :
  415.       ((mtmp = m_at(x,y)) && (!mtmp->minvis || csi) &&
  416.          (!mtmp->mhide || !o_at(mtmp->mx,mtmp->my)))
  417.       ? cansee(x,y) : 0);
  418. }
  419.  
  420. #ifdef NEWSCR
  421. pobj(obj) register struct obj *obj; {
  422. register int show = (!obj->oinvis || See_invisible) &&
  423.       cansee(obj->ox,obj->oy);
  424.    if(obj->odispl){
  425.       if(obj->odx != obj->ox || obj->ody != obj->oy || !show)
  426.       if(!vism_at(obj->odx,obj->ody)){
  427.          newsym(obj->odx, obj->ody);
  428.          obj->odispl = 0;
  429.       }
  430.    }
  431.    if(show && !vism_at(obj->ox,obj->oy)){
  432.       atl(obj->ox,obj->oy,obj->olet);
  433.       obj->odispl = 1;
  434.       obj->odx = obj->ox;
  435.       obj->ody = obj->oy;
  436.    }
  437. }
  438. #endif NEWSCR
  439.  
  440. unpobj(obj) register struct obj *obj; {
  441. /*    if(obj->odispl){
  442.       if(!vism_at(obj->odx, obj->ody))
  443.          newsym(obj->odx, obj->ody);
  444.       obj->odispl = 0;
  445.    }
  446. */
  447.    if(!vism_at(obj->ox,obj->oy))
  448.       newsym(obj->ox,obj->oy);
  449. }
  450.  
  451. seeobjs(){
  452. register struct obj *obj, *obj2;
  453.    for(obj = fobj; obj; obj = obj2) {
  454.       obj2 = obj->nobj;
  455.       if(obj->olet == FOOD_SYM && obj->otyp >= CORPSE
  456.          && obj->age + 250 < moves)
  457.             delobj(obj);
  458.    }
  459.    for(obj = invent; obj; obj = obj2) {
  460.       obj2 = obj->nobj;
  461.       if(obj->olet == FOOD_SYM && obj->otyp >= CORPSE
  462.          && obj->age + 250 < moves)
  463.             useup(obj);
  464.    }
  465. }
  466.  
  467. seemons(){
  468. register struct monst *mtmp;
  469.    for(mtmp = fmon; mtmp; mtmp = mtmp->nmon){
  470.       pmon(mtmp);
  471. #ifndef NOWORM
  472.       if(mtmp->wormno) wormsee(mtmp->wormno);
  473. #endif NOWORM
  474.    }
  475. }
  476.  
  477. pmon(mon) register struct monst *mon; {
  478. register int show =
  479.    ((!mon->minvis || See_invisible) &&
  480.       (!mon->mhide || !o_at(mon->mx,mon->my)) &&
  481.       cansee(mon->mx,mon->my))
  482.     || (Blind && Telepat);
  483.    if(mon->mdispl){
  484.       if(mon->mdx != mon->mx || mon->mdy != mon->my || !show)
  485.          unpmon(mon);
  486.    }
  487.    if(show && !mon->mdispl){
  488.       atl(mon->mx,mon->my,
  489.         mon->mimic ? mon->mimic : mon->data->mlet);
  490.       mon->mdispl = 1;
  491.       mon->mdx = mon->mx;
  492.       mon->mdy = mon->my;
  493.    }
  494. }
  495.  
  496. unpmon(mon) register struct monst *mon; {
  497.    if(mon->mdispl){
  498.       newsym(mon->mdx, mon->mdy);
  499.       mon->mdispl = 0;
  500.    }
  501. }
  502.  
  503. nscr()
  504. {
  505.    register int x,y;
  506.    register struct rm *room;
  507.  
  508.    if(u.uswallow || u.ux == FAR || flags.nscrinh) return;
  509.    pru();
  510.    for(y = scrly; y <= scrhy; y++)
  511.       for(x = scrlx; x <= scrhx; x++)
  512.          if((room = &levl[x][y])->new) {
  513.             room->new = 0;
  514.             at(x,y,room->scrsym);
  515.          }
  516.    scrhx = scrhy = 0;
  517.    scrlx = COLNO;
  518.    scrly = ROWNO;
  519. }
  520.  
  521. char oldbot[100], newbot[100];      /* 100 >= COLNO */
  522. extern char *eos();
  523. bot()
  524. {
  525. register char *ob = oldbot, *nb = newbot;
  526. register int i;
  527.     if(flags.botlx) *ob = 0;
  528.     flags.botl = flags.botlx = 0;
  529.     (void) sprintf(newbot,
  530.         "Level %-2d  Gold %-5lu  Hp %3d(%d)  Ac %-2d  Str ",
  531.         dlevel, u.ugold, u.uhp, u.uhpmax, u.uac);
  532.     if(u.ustr>18) {
  533.         if(u.ustr>117)
  534.         (void) strcat(newbot,"18/**");
  535.         else
  536.         (void) sprintf(eos(newbot), "18/%02d",u.ustr-18);
  537.     } else
  538.         (void) sprintf(eos(newbot), "%-2d   ",u.ustr);
  539.     (void) sprintf(eos(newbot), "  Exp %2d/%-5lu ", u.ulevel,u.uexp);
  540.     (void) strcat(newbot, hu_stat[u.uhs]);
  541.     if(flags.time)
  542.         (void) sprintf(eos(newbot), "  %ld", moves);
  543.     if(strlen(newbot) >= COLNO) {
  544.         register char *bp0, *bp1;
  545.         bp0 = bp1 = newbot;
  546.         do {
  547.             if(*bp0 != ' ' || bp0[1] != ' ' || bp0[2] != ' ')
  548.                 *bp1++ = *bp0;
  549.         } while(*bp0++);
  550.     }
  551.     for(i = 1; i<COLNO; i++) {
  552.       if(*ob != *nb){
  553.          curs(i,ROWNO+2);
  554.          (void) myputchar(*nb ? *nb : ' ');
  555.          curx++;
  556.       }
  557.       if(*ob) ob++;
  558.       if(*nb) nb++;
  559.    }
  560.    (void) strcpy(oldbot, newbot);
  561. }
  562.  
  563. #ifdef WAN_PROBING
  564. mstatusline(mtmp) register struct monst *mtmp; {
  565.    pline("Status of %s: ", monnam(mtmp));
  566.    pline("Level %-2d  Gold %-5lu  Hp %3d(%d)  Ac %-2d  Dam %d",
  567.        mtmp->data->mlevel, mtmp->mgold, mtmp->mhp, mtmp->orig_hp,
  568.        mtmp->data->ac, (mtmp->data->damn + 1) * (mtmp->data->damd + 1));
  569. }
  570. #endif WAN_PROBING
  571.  
  572. cls(){
  573.    if(flags.topl == 1)
  574.       more();
  575.    flags.topl = 0;
  576.  
  577.    clear_screen();
  578.  
  579.    flags.botlx = 1;
  580. }
  581.  
  582.